<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>shell 练习8 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>shell 练习8</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/shell练习/">shell练习</a>
			</span>
		
	</div>

	

	
		<p>需求： 两台web:A和B机器，其中一台B只打算跑附件（大多为图片），另一台A跑除了附件外的其他东西。其中附件会在A上生成，默认附件会通过A机器访问，但当我们更改某个附件的标志位时，那么附件则会跑到B上去访问。 假如提供给我们了将要在B上跑的附件列表和更改这些附件的标志位的一个sql文件，那么我们如何做呢？</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#! /bin/bash</span></div><div class="line"><span class="comment">## 1. rsync att to remote server.</span></div><div class="line"><span class="comment">## 2. execute the sql for changing tag 0 to 1.</span></div><div class="line"><span class="comment">## 3. delete the file att_list and sql.</span></div><div class="line">base_dir=/data/wwwroot/bbs.xxx.com/data</div><div class="line">r_dir=160.11.274.32::img</div><div class="line">d=`date +%Y%m%d`</div><div class="line"><span class="comment">#文件列表的文件</span></div><div class="line">f_list=<span class="variable">$base_dir</span>/attachment_move_list.php   </div><div class="line"><span class="comment">#更改附件标志位的sql文件</span></div><div class="line">f_sql=<span class="variable">$base_dir</span>/attachment_move_sql.php  更改附件标志位的sql文件</div><div class="line">file_dir=<span class="variable">$base_dir</span>/oldatt_list_sql</div><div class="line"><span class="keyword">if</span> [ ! -d <span class="variable">$file_dir</span> ] ; <span class="keyword">then</span></div><div class="line">    mkdir <span class="variable">$file_dir</span></div><div class="line"><span class="keyword">fi</span></div><div class="line"><span class="keyword">if</span> [ ! -f <span class="variable">$f_list</span> ] || [ ! -f <span class="variable">$f_sql</span> ]; <span class="keyword">then</span></div><div class="line">    <span class="built_in">exit</span></div><div class="line"><span class="keyword">fi</span></div><div class="line">grep -v <span class="string">'exit()'</span> <span class="variable">$f_list</span> |sed <span class="string">'s#/data/wwwroot/bbs.xxx.com/data/attachment/forum#.#'</span>  &gt; /tmp/1.txt</div><div class="line"><span class="built_in">cd</span> <span class="variable">$base_dir</span>/attachment/forum</div><div class="line">rsync -aL --files-from=/tmp/1.txt ./ <span class="variable">$r_dir</span>/</div><div class="line">/bin/mv <span class="variable">$f_list</span> <span class="variable">$file_dir</span>/<span class="variable">$d</span>.list</div><div class="line">grep -v <span class="string">'exit()'</span> <span class="variable">$f_sql</span> &lt; /tmp/2.txt</div><div class="line">mysql -h192.168.1.11 -uuser -p<span class="string">'passwd'</span> bbs &amp;lt; /tmp/2.txt</div><div class="line">/bin/mv <span class="variable">$f_sql</span> <span class="variable">$file_dir</span>/<span class="variable">$d</span>.sql</div></pre></td></tr></table></figure>

	

	
		<span class="different-posts"><a href="/2017/10/12/Shell 练习/8. shell 练习/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
